﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SongSharp.Domain.Objects;
using TagLib;

namespace SongSharp.Domain.Tagging
{
    public struct TagInfo
    {
        public string Title { get; set; }
        public string Artist { get; set; }
        public string Album { get; set; }
        public string Year { get; set; }
        public TimeSpan Length { get; set; }
    }

    public abstract class TagReader
    {
        public static TagInfo Read(Track track)
        {
            TagInfo tags = new TagInfo();
            try {
                File file = File.Create(track.Url);
                Tag t = file.GetTag(TagTypes.Id3v2);
                tags.Length = file.Properties.Duration;
                file.Dispose();

                tags.Artist = t.FirstPerformer;
                tags.Album = t.Album;
                tags.Title = t.Title;
                tags.Year = t.Year.ToString();

            } catch (Exception) {}

            return tags;
        }
    }
}
